package com.animal.service.impl;

import com.animal.entity.pojo.ABlog;
import com.animal.entity.pojo.Reply;
import com.animal.entity.vo.ABlogVo;
import com.animal.mapper.ABlogMapper;
import com.animal.mapper.ReplyMapper;
import com.animal.service.ABlogService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ABlogServiceImpl implements ABlogService {
    @Autowired
    private ABlogMapper aBlogMapper;

    @Autowired
    private ReplyMapper replyMapper;

    @Override
    public List<ABlogVo> getBlog() {
        List<ABlog> blog = aBlogMapper.getBlog();
        List<ABlogVo> vos  = new ArrayList<>();
        for (ABlog aBlog : blog) {
            ABlogVo vo = new ABlogVo();
            BeanUtils.copyProperties(aBlog,vo);

            List<Reply> allByRemarkId = replyMapper.findAllByRemarkId(aBlog.getId());

            vo.setReplyList(allByRemarkId);
            vos.add(vo);
        }

        return vos;
    }

    @Override
    public boolean addBlog(ABlog aBlog) {
        int i = aBlogMapper.addBlog(aBlog);
        if (i>0) {
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean delete(Integer id) {
        int count = aBlogMapper.delete(id);
        if(count>0){
            return true;
        }else {
            return false;
        }

    }

    @Override
    public boolean deleteByIds(List<Integer> ids) {
        int count = aBlogMapper.deleteByIds(ids);
        if(count>0){
            return true;
        }else {
            return false;
        }

    }
}
